<?php
$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'产品管理'=>array($this->pre_module_url.'/productSale/admin'),
	'分类管理'=>array($this->pre_module_url.'/category/admin'),
);
//载入规格模型
$attmod = AttMod::model()->getMod();
//模型数据处理成字符串,JS调用
$sttmodestr = "";
foreach($attmod as $key=>$val){
	$sttmodestr .= '<input type="radio" class="att_mod radio" name="zmd_id" value="'.$key.'" ><label class="c_999 mr20">'.$val.'</label>';
}
?>



<!--排序表单 -->
<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>$this->pre_module_url.'/category/update',
	'id'=>'category-form',
	'method'=>'post',
)); ?>
	 <ul class="main_class">
	 	<li class="main_type">
			<div class="cate_hd mem_bgx">
				<ul class="hd f_r t_c">
					<li class="w_240 f_l">分类名称</li>
					<li class="w_180 f_l">分类图标/模型</li>
					<li class="w_140 f_l">移动</li>
					<li class="w_140 f_l">查看分类下宝贝</li>
					<li class="w_120 f_l">操作</li>
				</ul>
			</div>
	 	</li>
	 	<div class="cate_th">
	 		<span class="c_666 f_r">注意：添加分类图片的规格为：186*27px</span>
	 		<span class="mem_bgx link_btn mr5">
	 			<a class="mem_bgx link_btn click" href="javascript:" onclick="addCate('0')" title="">添加一级分类</a>
	 			<b class="mem_bgx left"></b><b class="mem_bgx right"></b>
	 		</span>
	 		<span class="mem_bgx link_btn mr5">
	 			<a class="mem_bgx link_btn click" href="javascript:" onclick="$('#category-form').submit()" title="">保存排序</a>
  				<b class="mem_bgx left"></b><b class="mem_bgx right"></b>
  			</span>
	 	</div>
		<?php $this->widget('zii.widgets.CListView', array(
			'dataProvider'=>Category::model()->loadTop(),
			'itemView'=>'_view',
			'emptyText'=>"",
			'enablePagination'=>'false',
			'template'=>'{items}',
			'itemsTagName'=>'ul',
			'itemsCssClass'=>'list_table list_table2 c_f',
			'htmlOptions'=>array('class'=>'type_list')
		)); 
		?>
	</ul>
<?php $this->endWidget(); ?>
	 	
	 	
<!-- 上传组件 -->
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js"></script>  
<!-- 弹框组件 -->
<link href="/js/artdialog/skins/default.css" rel="stylesheet" />
<script src="/js/artdialog/artDialog.min.js"></script>

<script>  
$(function () {   
    //列表折叠
    $('.fold').live('click',function(){
        $(this).toggle(
    	    function(){
        	    $(this).parent().parent().next('.child').show();
				$(this).parent().toggleClass('open');
        	},
    	    function(){
       		 	$(this).parent().parent().next('.child').hide();
          		$(this).parent().toggleClass('open');
        	}
     	)
    }); 
    //移动排序下移
    $('.downlist').live('click',function(){
        var a = $(this).parent().parent().parent();
		a.next('li').after(a);
    });
    //移动排序上移
    $('.uplist').live('click',function(){
        var a = $(this).parent().parent().parent();
		a.prev('li').before(a);
    });
}); 
//弹框@param pid 父ID，@param level 级别
function addCate(pid){
	art.dialog({
	    title: '新建分类',
	    content: '分类名称:<input type="text" id="newtitle" name="name"/>',
	    height: '100px',
	    width: '300px',
	    okValue: '保存',
	    cancelValue: '取消',
	    cancel: function () {},
	    ok:function () {
			var a = $('#newtitle').val();
			window.location.href = "/manage/category/create/pid/"+pid+"/title/"+a;
		}
	});
}
//ajax新建分类
$('.add_cate_btn').live('click',function(){
	var catid = $(this).attr('catid');
	var level = $(this).attr('level');
	var object = $(this);
    $.ajax({
    	type: "GET",
    	url: '<?php echo $this->pre_module_url ?>/category/create',
    	data: "ajax=deleteajax&pid="+catid,
    	success: function(msg){
    		if(msg=='-1'){
    			art.dialog({
    			    title: '错误',
    			    content: '<?php //echo t('Failed')?>'
    			}).time(1000);
		    }else{
		    	var str = '<li class="item"><ul class="c_f p_5 f_r cate">'
		    			+'	<li class="w_240 f_l t_l">';
		    		if(level==1){
		    			str +=' <div class="w_20 f_l">&nbsp;</div><span class="mem_ico fold ico_fold"></span><span>&nbsp;';
		    		}else if(level==2){
		    			str +=' <div class="w_40 f_l">&nbsp;</div><span class="mem_ico fold ico_del"></span><span>&nbsp;';
			    	}			
		    		str +='		<input 0="" type="text" class="cate_title" catid="'+msg+'" value="分类名称" name="Category[zca_title][]" id="Category_zca_title"></span>	'
		    			+'	</li>'
		    			+'	<li class="w_180 f_l t_c">'
		    			+'		<a class="c_06c bind_att_mod_button" zca_id="'+msg+'" href="javascript:">绑定规格模型</a>'							
		    			+'	</li>'
		    		if(level==1){
		    			str +='	<li class="w_140 f_l t_c c">&nbsp;<div class="w_20 f_l">&nbsp;</div>'
		    		}else{
		    			str +='	<li class="w_140 f_l t_c c">&nbsp;<div class="w_40 f_l">&nbsp;</div>'
			    	}
		    		str +='		<a class="mem_ico uplist ord_7" title="向上移动" href="javascript:">&nbsp;</a>'
		    			+'		<input type="hidden" value="'+msg+'" name="Category[zca_id][]" id="Category_zca_id">'		
		    			+'		<a class="mem_ico downlist ord_8" title="向下移动" href="javascript:">&nbsp;</a>'
		    			+'	</li>'
		    			+'	<li class="w_140 f_l t_c">&nbsp;'
		    			+'		<a class="c_666" href="/manage/product/admin/Product%5Bcateid3%5D/'+msg+'">宝贝列表</a>'
		    			+'	</li>'
		    			+'	<li class="w_120 f_l t_c">&nbsp;'
		    			+'		<a class="del_date c_06c" href="/manage/category/delete/id/'+msg+'">删除</a>'
		    			+'		<a class=" c_06c" href="/manage/category/updateSeo/id/'+msg+'">编辑</a>'
		    			+'	</li>'
		    			+'	</ul>';
		    		if(level==1){
		    			str +='<div class="child d_n">'
			    			+'		<div class="type_list" id="yw26">'
			    			+'			<ul class=""><span class="empty"></span></ul>'
			    			+'			<div class="keys" style="display:none" title="/manage/category/admin"></div>'
			    			+'		</div>'
			    			+'		<div class="cate_addbtn">'
			    			+'			<div class="w_20 f_l">&nbsp;</div>'
			    			+'			<div class="w_20 f_l">&nbsp;</div>'
			    			+'			<span class="mem_bgx link_btn mr5">'
			    			+'				 	<a class="mem_bgx link_btn add_cate_btn click" href="javascript:" catid="'+msg+'" level="2" title="">添加三级分类</a>'
			    			+'					<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'
			    			+'			</span>'
			    			+'		</div>'
			    			+'	</div>';
			    	}
		    		str +='</li>';
		    	object.parent().parent().prev('div').children('ul').append(str);
			}
    	}
    })
})
//ajax删除
$('.del_date').live('click',function(){
	var urls = $(this).attr('href') ;
	if(!confirm("确认删除")){
		return false;
	}
	var th = $(this);

    $.ajax({
    	type: "GET",
    	url: urls,
    	data: "ajax=deleteajax",
    	success: function(msg){
    		if(msg==1){
    			th.parent().parent().parent().remove();
				return false;
		    }else{
		    	alert(msg)
			}
    	}
    })
	return false;
});
//ajax修改分类标题
$('.cate_title').live('change',function(){
	var id = $(this).attr('catid') ;
	var value = $(this).val() ;
    $.ajax({
    	type: "GET",
    	url: "<?php echo $this->pre_module_url?>/category/update",
    	data: "ajax=deleteajax&id="+id+"&title="+value,
    	success: function(msg){
    		if(msg==1){
    			art.dialog({
    			    title: '提示',
    			    content: '<?php echo t('Save Success')?>'
    			}).time(1000);
        	}else{
        		art.dialog({
    			    title: '错误',
    			    content: msg
    			}).time(300);
        	}
    	}
    })
	return false;
});
//绑定分类模型
$('.bind_att_mod_button').live('click',function(){
	var zcalink = $(this);
	art.dialog({
	    title: '绑定模型',
	    content: '<p class="c_666">请选择要绑定的规格属性模型，模型的规格属性将添加到当前分类的规格属性！</p><?php echo $sttmodestr ?>',
	    //height: '300px',
	    width: '500px',
	    okValue: '保存',
	    cancelValue: '取消',
	    cancel: function () {},
	    ok:function () {
		    var catid = zcalink.attr('zca_id');
			var modid = $('.att_mod:checked').val();
			var modtitle = $('.att_mod:checked').next('label').text();
			$.ajax({
		    	type: "GET",
		    	url: "/manage/category/ajaxBindAttMod",
		    	data: "zca_id="+catid+"&zmd_id="+modid,
		    	success: function(msg){
		    		if(msg==1){
			    		var str = '<label class="c_999 bind_att_mod_button" zca_id="'+catid+'" >'+modtitle+'</label>';
		    			zcalink.replaceWith(str);
						return false;
				    }else{
				    	alert(msg)
					}
		    	}
		    })
		}
	});
})

</script> 

